﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DBAccessor.Accessor;
using AlanUtilities;
using DBList.Entities;
using DBList;
using System.Collections.Generic;

public partial class WLSendGoods : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		String strUID = OperateControl.PickupAvaiableUserID(this);
		if (!IsPostBack)
		{
			operaterLabel.Text = strUID;
			int	nUID;
			int.TryParse(strUID, out nUID);
			MemberAccessor memberSystem = new MemberAccessor();
			UserData usrData = memberSystem.GetMemberInfo(nUID);
			if(usrData.GroupId != 1 && usrData.GroupId != 2 && usrData.GroupId != 4){
				btnReturn.Visible = true;
				Label2.Text = @"你没有权限！";
				btnReturn.Focus();

				btnSubmit.Visible = false;
				trBarCode.Visible = false;
				trKind.Visible = false;
				trName.Visible = false;
				trPhone.Visible = false;
				trAddress.Visible = false;
				trSingleMoney.Visible = false;
				trComment.Visible = false;
				trDanHao.Visible = false;
				
				return;
			}
			string strTiaoMa = Request.QueryString.Get("ArticleId");
			if (strTiaoMa != null && strTiaoMa.Length > 0)
			{
				string strKindName = Request.QueryString.Get("KindName");
				MsgAccessor msgAcce = new MsgAccessor();
				TiaoMaRecord tmRec = msgAcce.GetOneTiaoMaRecord(strTiaoMa, null);
				if (tmRec.IsActivated && tmRec.TiaoMa > 0)
				{
					CPNAccessor cpnAcce = new CPNAccessor();
					ClassData kdData = cpnAcce.GetGoodsKindInfo(tmRec.Kind);

					tbSingleMoney.Text = kdData.ClassMoney.ToString();
					tbComment.Text = tmRec.CsterComment;

					tbBarCode.Text = strTiaoMa;
					tbKind.Text = strKindName;
					string strUserInfo = tmRec.ConsumerInfo;

					char[] pSplit = new char[1];
					pSplit[0] = '/';
					string[] liststr = strUserInfo.Split(pSplit);
					if (liststr.Length >= 3)
					{
						tbName.Text = liststr[0];
						tbPhone.Text = liststr[1];
						tbAddress.Text = liststr[2];
					}
					else if (liststr.Length == 2)
					{
						tbName.Text = liststr[0];
						tbPhone.Text = liststr[1];
					}
					else if (liststr.Length == 1)
					{
						tbName.Text = liststr[0];
					}
				}
			}
		}
	}
	protected void btnSubmit_Click(object sender, EventArgs e)
	{
		string strID = operaterLabel.Text;
		int		nOpeID;
		if (int.TryParse(strID, out nOpeID))
		{
			string strDanHao = tbDanHao.Text.Trim();
			if(strDanHao.Length < 3){
				Label2.Text = @"请输入物流单号！";
			}
			else {
				MsgAccessor msgAcce = new MsgAccessor();
				int nRet = msgAcce.SubmitSendGDH(nOpeID, tbBarCode.Text, tbDanHao.Text.Trim());
				if (nRet == 0)
				{
					btnReturn_Click(null, null);
				}
				else if (nRet == -100 || nRet == -101)
				{
					Label2.Text = @"你没有权限！";
				}
				else
				{
					Label2.Text = @"操作失败！";
				}
			}
		}
	}
	protected void btnReturn_Click(object sender, EventArgs e)
	{
		Response.Redirect(@"NoSendGDetail.aspx");
	}
}
